<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        * {
            margin: 0;
            padding: 0;
        }
        li {
            list-style: none;
            float: left;
            width: 134px;
            height: 30px;
            line-height: 30px;
            text-align: center;
        }
        li.ac {
            background-color: #ccc;
        }
        img {
            width: 404px;
            height: 300px;
        }
        #box {
            width: 404px;
            margin: 0 auto;
        }
        ul {
            border: 1px solid #999;
            height: 30px;
        }
        .wrap div {
            display: none;
        }
        .wrap div.ac {
            display: block;
        }
    </style>
</head>
<body>
    <div id="box">
        <ul>
            <li class="ac">女枪</li>
            <li>阿狸</li>
            <li>阿卡丽</li>
        </ul>
        <div class="wrap">
            <div class="ac"><img src="../nvq.jpg" alt=""></div>
            <div><img src="../ali.jpg" alt=""></div>
            <div><img src="../akali.jpg" alt=""></div>
        </div>
    </div>
    <script>
        
        class Tab {
            constructor (id){
                this.box = document.querySelector(id)
                this.list = box.querySelectorAll('li')
                this.imgs = box.querySelectorAll('.wrap div')
                //new的时候就要默认执行的方法，就可以在构造函数里调用
                this.callList()
            }
            callList (){
                this.list.forEach( (btn,index) => {
                    btn.onclick = () =>{
                        this.changge(index)
                    }
                });
            }
            changge(index){
                for(var i=0;i<this.imgs.length;i++){
                    this.list[i].classList.remove('ac')
                    this.imgs[i].classList.remove('ac')
                }
                this.list[index].classList.add('ac')
                this.imgs[index].classList.add('ac')
            }
        }

        new Tab()
    </script>
</body>
</html>